<template>
    <div class="company_auth">
        <van-nav-bar title="企业认证" left-text="返回" right-text="提交" left-arrow @click-left="onClickLeft" @click-right="company_auth"/>
        <div class="con">
            <div class="wrap">

                <div class="item">
                    <van-cell-group>
                        <van-cell required title="公司LOGO"><van-uploader :after-read="onRead"><img :src="formData.logo" alt=""></van-uploader></van-cell>
                        <van-cell required title="营业执照"><van-uploader :after-read="onRead2"><img :src="formData.license_img" alt=""></van-uploader></van-cell>
                    </van-cell-group>
                    <van-cell-group class="line">
                        <van-field v-model="formData.name" clearable required label="公司名称" placeholder="请输入公司名称" />
                        <van-field v-model="formData.short_name" clearable label="公司简称" placeholder="请输入公司简称" />
                        <van-field v-model="formData.address" clearable required label="公司地址" placeholder="请输入公司地址" />
                        <van-field v-model="formData.phone" clearable required label="公司电话" placeholder="请输入公司电话" />
                        <van-field v-model="formData.contact_person" clearable required label="联系人" placeholder="请输入公司联系人" />
                        <van-field v-model="formData.intro" label="公司介绍" type="textarea" placeholder="请输入与公司介绍" rows="3" autosize/>
                    </van-cell-group>
                </div>
                  <div class="text">
                    <p><span>1</span><em>认证商家拥有绿色通道,发布兼职快速上架</em></p>
                    <p><span>2</span><em>每天可以发布十条兼职,满足招聘需求</em></p>
                    <p><span>3</span><em>享有认证专属服务,增强信任感</em></p>
                    <p><span>4</span><em>我们会优先推送已认证的企业</em></p>
                    <p><span>5</span><em>只有认证商家才能享受置顶服务</em></p>
                </div>
            </div>

        </div>

    </div>
</template>

<script>
    import axios from 'axios';
    import qs from 'qs'
    import Vue from 'vue'
import { Cell, CellGroup,Uploader,Field,Dialog} from 'vant';

Vue.use(Cell).use(CellGroup).use(Uploader).use(Field).use(Dialog);
    export default {
        data(){
          return{
              formData:{
                  logo:'/img/no.jpg',
                  license_img:'/img/no_img.jpg',
                  uid:(JSON.parse(localStorage.getItem('user')).uid),
                  type:(JSON.parse(localStorage.getItem('user')).type),
                  name:'',
                  short_name:'',
                  address:'',
                  phone:'',
                  contact_person:'',
                  intro:''

              }
          }
        },
        methods: {
            onRead(file){
                this.upload(file.file,'logo')
            },
            onRead2(file){
                this.upload(file.file,'license_img')
            },
            onClickLeft() {
                history.back()
            },
            upload(file,taget){
                let Form = new FormData();
                Form.append('avatar', file);
                axios.post('/api/upload',Form).then(res=>{
                    if(res.data.err_code ==0){
                        this.formData[taget]  = res.data.data.imgUrl;
                    }else{
                        this.$toast({message: res.data.err_msg})
                    }
                })
            },
            company_auth(){
                if(!this.formData.logo || this.formData.logo=='/img/no.jpg'){
                    Dialog.alert({message:"请先上传公司logo"})
                    return;
                };
                if(!this.formData.license_img || this.formData.logo=='/img/no_img.jpg'){
                    Dialog.alert({message:"请先上传公司营业执照照片"})
                    return;
                };
                this.$post('/api/company/auth',this.formData).then(res=>{
                    console.log(res)
                    if(res.data.err_code == 0){
                        Dialog.alert({message:res.data.err_msg}).then(()=>{
                            this.$router.replace({name:'company'})
                        })
                    }else{
                        Dialog.alert({message:res.data.err_msg})
                    }
                }).catch(err=>{
                    this.$toast({message:err})
                })
            }
        },
        created(){
            document.body.style.backgroundColor='rgb(239, 243, 246)'
        }
    }
</script>

<style lang="less" scoped>
   @import "../../public/css/company_auth.less";

</style>
